//
//  FontSpacingViewController.m
//  20170207
//
//  Created by xuPeng on 2017/9/7.
//  Copyright © 2017年 一直丶黑曼巴. All rights reserved.
//
#import "Header.h"
#import "FontSpacingViewController.h"

@interface FontSpacingViewController ()

@end

@implementation FontSpacingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置字体和行间距
    UILabel * lable = [[UILabel alloc]initWithFrame:CGRectMake((PW -300)/2, 100, 300, 200)];
    lable.text = @"峰峦如聚,波涛如怒,山河表里潼关路.望西都,意踌躇,伤心秦汉经行处,宫阙万间都做了土,兴百姓,苦,亡,百姓苦.";
    
    lable.numberOfLines = 0;
    lable.font = [UIFont systemFontOfSize:14];
    lable.backgroundColor = [UIColor lightGrayColor];
    NSMutableAttributedString * str = [[NSMutableAttributedString alloc]initWithString:lable.text attributes:@{NSKernAttributeName:@(8.0)}];
    
    //设置某写字体的颜色
    //NSForegroundColorAttributeName 设置字体颜色
    NSRange blueRange = NSMakeRange([[str string] rangeOfString:@"Frank_chun"].location, [[str string] rangeOfString:@"Frank_chun"].length);
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:blueRange];
    NSRange blueRange1 = NSMakeRange([[str string] rangeOfString:@"438637472"].location, [[str string] rangeOfString:@"438637472"].length);
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:blueRange1];
    
    //设置每行之间的间距
    //NSParagraphStyleAttributeName 设置段落的样式
    NSMutableParagraphStyle * par = [[NSMutableParagraphStyle alloc]init];
    [par setLineSpacing:30];
    
    //为某一范围内文字添加某个属性
    //NSMakeRange表示所要的范围,从0到整个文本的长度
    [str addAttribute:NSParagraphStyleAttributeName value:par range:NSMakeRange(0, lable.text.length)];
    [lable setAttributedText:str];
    [self.view addSubview:lable];
}


@end
